package com.imooc.security.order;

import com.google.common.collect.Ordering;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName OrderController
 * @Description TODO 订单服务
 * @Author wushaopei
 * @Date 2021/5/2 20:39
 * @Version 1.0
 */
@RestController
@RequestMapping("/orders")
@Slf4j
public class OrderController {

    private RestTemplate restTemplate = new RestTemplate();

    @PostMapping
    public OrderInfo create(@RequestBody OrderInfo info,
//                            @RequestHeader String username){
//                            @AuthenticationPrincipal User user){
                            @AuthenticationPrincipal(expression = "#this.id") Long id){

//        log.info("user is {}" ,user.getId());
        log.info("user is {}",id);
//        PriceInfo priceInfo  = restTemplate.getForObject("http://localhost:9080/prices/" + info.getProductId(),PriceInfo.class);
//        log.info("price is:{}",priceInfo.getPrice());
        OrderInfo orderInfo = new OrderInfo();
//        orderInfo.setUsername(username);
        return orderInfo;
    }

    @GetMapping("/{id}")
    public String  getInfo(@PathVariable Long id , @RequestHeader String username){
        log.info("user is " + username);
        log.info("orderId is " + id);
//        OrderInfo info = new OrderInfo();
//        info.setUsername(username);
//        info.setId(id);
//        info.setProductId(id);
        return String.valueOf(id);
    }
}
